package com.qianchang.microfinance.view.mine.loan;

import android.content.Context;
import android.view.View;

import com.dm.library.adapter.CommonAdapter;
import com.dm.library.adapter.CommonViewHolder;
import com.dm.library.utils.FormatUtil;
import com.dm.library.widgets.OneLineLinearLayout;
import com.qianchang.microfinance.R;
import com.qianchang.microfinance.bean.RepaymentRecordBean;

import java.util.List;

/**
 * 版 权: 深圳市迪蒙网络科技有限公司
 * 描 述:
 * 修 改 人: zhoulai
 * 修改时间: 2017/7/6 9:22
 */


class RepaymentRecordAdapter extends CommonAdapter<RepaymentRecordBean.ListBean> {

    private List<RepaymentRecordBean.ListBean> list;

    RepaymentRecordAdapter(Context mContext, List<RepaymentRecordBean.ListBean> beanList, int layoutRes) {
        super(mContext, beanList, layoutRes);
        this.list = beanList;
    }

    @Override
    protected void convert(CommonViewHolder holder, RepaymentRecordBean.ListBean bean, int position) {
        if (bean == null) bean = new RepaymentRecordBean.ListBean();
        String strDate;
        if (bean.getRealPayDate() != null && bean.getRealPayDate().length() >= 10) {
            strDate = bean.getRealPayDate().substring(0, 10);
        } else {
            strDate = bean.getRealPayDate();
        }
        holder.setText(R.id.tv_date_time, strDate);
        holder.setText(R.id.tv_period, bean.getPeriod()+"/"+ 12);
        OneLineLinearLayout ollReplyAdvance = holder.getView(R.id.oll_reply_type_and_amount);

        String replyMode = "";
        //  private String mode;//还款记录的还款类型有4种，包括：0正常还款、1逾期还款、2全部提前还款、3部分提前还款；
        switch (bean.getMode()) {
            case 0:
                replyMode = "正常还款";
                break;
            case 1:
                replyMode = "逾期还款";
                break;
            case 2:
                replyMode = "全部提前还款";
                break;
            case 3:
                replyMode = "部分提前还款";
                break;
            default:
                replyMode = "正常还款";
                break;

        }
        ollReplyAdvance.setLeftContent(replyMode);
        ollReplyAdvance.setRightContent(FormatUtil.numKbPointFormat(bean.getPaidTotal()));

        OneLineLinearLayout ollPrincipal = holder.getView(R.id.oll_principal);
        ollPrincipal.setRightContent(FormatUtil.numKbPointFormat(bean.getPaidPrincipal()));//本金
        OneLineLinearLayout ollInterest = holder.getView(R.id.oll_interest);
        ollInterest.setRightContent(FormatUtil.numKbPointFormat(bean.getPaidInterest()));//lixi

        OneLineLinearLayout ollOverdueCost = holder.getView(R.id.oll_overdue_cost);//逾期费用
        if (bean.getPaidOverdue() != 0) {
            ollOverdueCost.setVisibility(View.VISIBLE);
            ollOverdueCost.setRightContent(FormatUtil.numKbPointFormat(bean.getPaidOverdue()));//
        } else {
            ollOverdueCost.setVisibility(View.GONE);
        }

        OneLineLinearLayout ollLiquidatedDamages = holder.getView(R.id.oll_liquidated_damages);//违约金
        if (bean.getPaidWeiyuejin() != 0) {
            ollLiquidatedDamages.setVisibility(View.VISIBLE);
            ollLiquidatedDamages.setRightContent(FormatUtil.numKbPointFormat(bean.getPaidWeiyuejin()));//
        } else {
            ollLiquidatedDamages.setVisibility(View.GONE);
        }

    }

}
